﻿// ***********************************************************************
// Project          : Micua.Infrastructure
// Assembly         : Micua.Core
// Author           : iceStone
// Created          : 2014-01-06 10:50 PM
// 
// Last Modified By : iceStone
// Last Modified On : 2014-01-06 10:50 PM
// ***********************************************************************
// <copyright file="Config.cs" company="Wedn.Net">
//     Copyright (c) Wedn.Net. All rights reserved.
// </copyright>
// <summary>配置文件信息类</summary>
// ***********************************************************************

using System.Collections.Generic;
using Micua.Utility;

namespace Micua.Core.Configuration
{
    /// <summary>
    /// 配置文件信息类
    /// </summary>
    public static partial class Config
    {
        /// <summary>
        /// 配置数据
        /// </summary>
        public static IDictionary<string, string> Configs
        {
            get
            {
                return ConfigHelper.Configs;
            }
        }

        #region 获取String类型配置信息 +static string GetString(string key, string def = "")
        /// <summary>
        /// 获取字符串类型配置信息
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>设置值</returns>
        public static string GetString(string key, string def = "")
        {
            return ConfigHelper.GetString(key, def);
        }
        #endregion

        #region 获取泛型类型的配置信息（JSON格式） +static T Get<T>(string key, T def = null) where T : class
        /// <summary>
        /// 获取泛型类型的配置信息（JSON格式）
        /// </summary>
        /// <remarks>
        ///  2013-11-23 14:27 Created By iceStone
        /// </remarks>
        /// <typeparam name="T">配置类型</typeparam>
        /// <param name="key">设置键</param>
        /// <param name="def">缺省值</param>
        /// <returns>制定类型的配置信息</returns>
        public static T Get<T>(string key, T def = null) where T : class
        {
            var json = GetString(key);
            try
            {
                return JsonHelper.Deserialize<T>(json);
            }
            catch (System.Exception)
            {
                return def;
            }
        }
        #endregion
    }
}